import React,{PureComponent} from 'react'
class App extends PureComponent{
  constructor(props){
    super(props)
    this.state={
      textVal:'',
      numberVal:null,
      selectVal:false
    }
    this.inputChange=this.inputChange.bind(this)
  }
  inputChange(e){
    console.log(e)
    console.dir(e.target)
    console.log(e.target.type)
    console.log(e.target.value)
    console.log(e.target.dataset.name)
    console.log(e.currentTarget.dataset.name)
    this.setState((preState)=>{
      return{
        [e.target.dataset.name]:e.target.type==='text' ?e.target.value : e.target.checked
      }
    })
  }
  render(){
    return(
      (
        <div>
          文本：<input type="text" value={this.state.textVal} onChange={this.inputChange} data-name={'textVal'}></input><br/>
          数字：<input type="number" value={this.numberVal} onChange={this.inputChange} data-name={'numberVal'}></input><br/>
          多选框：<input type="checkbox" checked={this.selectVal}
          onChange={this.inputChange} data-name={'selectVal'}></input><br/>
        </div>
      )
    )
  }
}
export default App